import { datashopAxios } from '@/utils/request'

// 数据项列表
export const reqDataItemList = (params: any): Promise<any> => {
  return datashopAxios({
    url: '/api/datashop/v3/data-item-products',
    method: 'get',
    params
  })
}

// 新增数据项
export const reqCreateDataItem = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products`,
    method: 'post',
    data
  })
}

// 更新数据项产品
export const reqEditDataItem = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products/${data.id}`,
    method: 'put',
    data
  })
}

// 数据项产品详情
export const reqDataItemInfo = (params: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products/${params.id}`,
    method: 'get',
    params
  })
}
// 获取已连接数据库表的数据量
export const reqDataItemColumns = (params: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v4/data-item-products/${params.id}/columns`,
    method: 'get',
    params: {
      page: 1,
      page_size: 199,
      ...params
    }
  }).then((res) => res.items)
}

// 更新数据项产品表字段
export const updateCoreFieldData = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products/${data.data_product_item_id}/columns/${data.column_id}`,
    method: 'put',
    data
  })
}
// 数据项编辑 下架
export const revokeDataItem = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products/${data.id}:revoke`,
    method: 'post',
    data
  })
}
// 数据项删除
export const reqDeleteDataItem = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products/${data.id}`,
    method: 'delete',
    data
  })
}
// 数据项上架/送审
export const onlineDataItem = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-product-audits`,
    method: 'post',
    data
  })
}
// 数据项审批通过
export const approveDataItemAudit = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-product-audits/${data.id}:approve`,
    method: 'post',
    data
  })
}
// 数据项审批驳回
export const rejectDataItemAudit = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-product-audits/${data.id}:reject`,
    method: 'post',
    data
  })
}
// 数据项编辑下架
export const delistDataItem = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products/${data.id}:revoke`,
    method: 'post',
    data
  })
}
// 新增查询样例数据
export const getDataItemExample = (params: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products/${params.data_product_item_id}/samples`,
    method: 'get',
    params
  })
}

// 筛选配置相关
// 规格列表
export const getDataItemSettingList = (params: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/specifications`,
    method: 'get',
    params
  })
}
// 新增聚合规格
export const addPolymerizeSetting = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products/${data.id}/polymerize-spec`,
    method: 'post',
    data
  })
}
// 编辑聚合规格
export const editPolymerizeSetting = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/specifications/polymerize-specs/${data.id}`,
    method: 'put',
    data
  })
}
// 查看聚合规格
export const getPolymerizeDetail = (params: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/specifications/polymerize-specs/${params.id}`,
    method: 'get'
  })
}

// 新增区域规格
export const addAreaSetting = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products/${data.id}/area-spec`,
    method: 'post',
    data
  })
}
// 编辑区域规格
export const editAreaSetting = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/specifications/area-specs/${data.id}`,
    method: 'put',
    data
  })
}
// 查看区域规格
export const getAreaDetail = (params: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/specifications/area-specs/${params.id}`,
    method: 'get'
  })
}

// 新增园区规格
export const addParkSetting = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products/${data.id}/park-specifications`,
    method: 'post',
    data
  })
}
// 编辑园区规格
export const editParkSetting = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/specifications/park-specs/${data.id}`,
    method: 'put',
    data
  })
}
// 查看园区规格
export const getParkDetail = (params: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/specifications/park-specs/${params.id}`,
    method: 'get'
  })
}

// 新增时间规格
export const addTimeSetting = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products/${data.id}/time-spec`,
    method: 'post',
    data
  })
}
// 编辑时间规格
export const editTimeSetting = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/specifications/time-specs/${data.id}`,
    method: 'put',
    data
  })
}
// 查看时间规格
export const getTimeDetail = (params: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/specifications/time-specs/${params.id}`,
    method: 'get'
  })
}

// 新增产业规格
export const addIndustrySetting = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products/${data.id}/industry-specifications`,
    method: 'post',
    data
  })
}
// 编辑产业规格
export const editIndustrySetting = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/specifications/industry-specs/${data.id}`,
    method: 'put',
    data
  })
}
// 查看产业规格
export const getIndustryDetail = (params: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/specifications/industry-specs/${params.id}`,
    method: 'get'
  })
}

// 新增企业白名单规格
export const addCompanyListSetting = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products/${data.id}/company-id-spec`,
    method: 'post',
    data
  })
}
// 编辑企业白名单规格
export const editCompanyListSetting = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/specifications/company-id-specs/${data.id}`,
    method: 'put',
    data
  })
}
// 查看企业白名单规格
export const getCompanyListDetail = (params: { id: any }): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/specifications/company-id-specs/${params.id}`,
    method: 'get'
  })
}
// 删除规格
export const deleteSetting = (data: { id: any }): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/specifications/${data.id}`,
    method: 'delete',
    data
  })
}

// 查看数据项产品表信息
export const getSyncSettings = (params: { id: any }): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products/${params.id}/table-info`,
    method: 'get',
    params
  })
}
// 更新数据项产品表信息
export const updateSyncSettings = (data: { id: any; sync_mode: string; sync_config?: any }): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products/${data.id}/table-info`,
    method: 'put',
    data
  })
}

// 更新数据项产品表字段列表
export const sortDataItemColumn = (data: any): Promise<any> => {
  return datashopAxios({
    url: `/api/datashop/v3/data-item-products/${data.id}/columns`,
    method: 'put',
    data
  })
}
